﻿namespace WordCloudClient.Common
{
    public class WinEditHelper
    {
        private readonly IDialogService _dialogService;

        public WinEditHelper(IDialogService dialogService)
        {
            _dialogService = dialogService;
        }
        /// <summary>
        /// 查看窗口
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="title"></param>
        /// <param name="address"></param>
        public void ExecutePreView(object? entity, string title, string address)
        {
            DialogParameters param = new()
            {
                { "Title", title },
                { "FristEntity", entity }
            };
            _dialogService.ShowDialog(address, param, r => { });
        }

        /// <summary>
        /// 执行编辑弹窗（自定义参数）
        /// </summary>
        /// <param name="param"></param>
        /// <param name="address"></param>
        /// <param name="messageInfo"></param>
        public void ExecuteEidt(DialogParameters param, string address, string messageInfo = "保存成功")
        {
            _dialogService.ShowDialog(address, param, r =>
            {
                if (r.Result == ButtonResult.OK)
                {
                    MessageTips.SuccessMessage(messageInfo);
                }
            });
        }
        /// <summary>
        /// 执行编辑弹窗（自定义参数）有返回参数
        /// </summary>
        /// <param name="param"></param>
        /// <param name="address"></param>
        /// <param name="messageInfo"></param>
        /// <param name="isShowMessage">是否弹出成功提示</param>
        /// <returns>返回参数</returns>
        public object ExecuteEidtHasReturnParameters(DialogParameters param, string address, string messageInfo = "保存成功",bool isShowMessage = false)
        {
            object o = new();
            _dialogService.ShowDialog(address, param, r =>
            {
                if (r.Result == ButtonResult.OK)
                {
                    if (isShowMessage)
                    {
                        MessageTips.SuccessMessage(messageInfo);
                    }
                    o = r.Parameters;
                }

            });
            return o;
        }
        /// <summary>
        /// 执行编辑弹窗（一个实体）
        /// </summary>
        /// <param name="entity">接收的实体</param>
        /// <param name="title">弹窗标题</param>
        /// <param name="address">弹窗对应的地址</param>
        /// <param name="messageInfo">保存成功提示信息</param>
        public void ExecuteEidt(object? entity, string title, string address, string messageInfo,string windowName)
        {
            DialogParameters param = new()
            {
                { "Title", title },
                { "FristEntity", entity }
            };
            _dialogService.ShowDialog(address, param, r =>
            {
                if (r.Result == ButtonResult.OK)
                {
                    MessageTips.SuccessMessage(messageInfo);
                }
            }, windowName);

        }

        /// <summary>
        /// 执行编辑弹窗（两个实体）
        /// </summary>
        /// <param name="fristEntity">接收的第一个实体</param>
        /// <param name="secondEntity">接收的第二个实体</param>
        /// <param name="title">弹窗标题</param>
        /// <param name="address">弹窗对应的地址</param>
        /// <param name="messageInfo">保存成功提示信息</param>
        public void ExecuteEidt(object? fristEntity, object? secondEntity, string title, string address, string messageInfo)
        {
            DialogParameters param = new()
            {
                { "Title", title },
                { "FristEntity", fristEntity },
                { "SecondEntity", secondEntity }
            };
            _dialogService.ShowDialog(address, param, r =>
            {
                if (r.Result == ButtonResult.OK)
                {
                    MessageTips.SuccessMessage(messageInfo);
                }
            });

        }
    }
}
